/*
 * Powered By XY
 * Since 2020
 */

package com.xy.biz.mes.controller;

import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.xy.biz.mes.domain.converter.ManufactureResultConverter;
import com.xy.biz.mes.domain.enums.ManufactureOrderStatusEnum;
import com.xy.biz.mes.domain.query.ManufactureResultQuery;
import com.xy.biz.mes.service.ManufactureResultService;
import com.xy.lang.enums.HandOverResultEnum;
import com.xy.lang.util.EnumUtils;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.xy.lang.domain.Page;
import com.xy.lang.domain.Result;
import com.xy.lang.validation.SaveChecks;
import com.xy.lang.validation.UpdateChecks;
import com.xy.lang.validation.annotation.Validatable;

import com.xy.biz.mes.domain.resp.GetManufactureResultResponse;
import com.xy.biz.mes.domain.req.GetManufactureResultRequest;
import com.xy.biz.mes.domain.req.ListManufactureResultRequest;
import com.xy.biz.mes.domain.req.SaveManufactureResultRequest;
import com.xy.biz.mes.client.ManufactureResultClient;

/**
 *
 *
 * @author zgy
 * @date 2022-2-11
 */
@Api(tags = "生产结果放行服务")
@Slf4j
@RestController
@RequestMapping("/api/mes/result")
public class ManufactureResultController implements ManufactureResultClient {

    @Autowired
    private ManufactureResultService manufactureResultService;

//    @Validatable(groups = {SaveChecks.class})
//    @PostMapping(value = "/save")
//    public Result<?> saveManufactureResult(@RequestBody SaveManufactureResultRequest request) {
//        return manufactureResultService.saveManufactureResult(ManufactureResultConverter.toBO(request));
//    }

    //	@Validatable(groups = {SaveChecks.class})
//	@PostMapping(value = "/save_all")
//	public Result<?> saveAllManufactureResult(@RequestBody Collection<SaveManufactureResultRequest> collection) {
//		return manufactureResultService.saveAllManufactureResult(ManufactureResultConverter.toBO(collection));
//	}
//
//	@Validatable(groups = {UpdateChecks.class})
//	@PostMapping(value = "/update")
//	public Result<?> updateManufactureResult(@RequestBody SaveManufactureResultRequest request) {
//		manufactureResultService.updateManufactureResult(ManufactureResultConverter.toBO(request));
//		return Result.success();
//	}
//
//	@Validatable
//	@PostMapping(value = "/delete")
//	public Result<?> deleteManufactureResult(@RequestBody GetManufactureResultRequest request) {
//		manufactureResultService.deleteManufactureResult(request.getManufactureResultId());
//		return Result.success();
//	}
//
//	@Validatable
//	@PostMapping(value = "/get")
//	@Override
//	public Result<GetManufactureResultResponse> getManufactureResult(@RequestBody GetManufactureResultRequest request) {
//		return Result.success(ManufactureResultConverter.toResponse(manufactureResultService.getManufactureResult(request.getManufactureResultId())));
//	}
//
//	@PostMapping(value = "/list_by_ids")
//	@Override
//	public Result<List<GetManufactureResultResponse>> listManufactureResultById(@RequestBody Collection<Long> collection) {
//		return Result.success(ManufactureResultConverter.toResponse(manufactureResultService.listManufactureResultById(collection)));
//	}
//
//	@PostMapping(value = "/list")
//	@Override
//	public Result<List<GetManufactureResultResponse>> listManufactureResult(@RequestBody ListManufactureResultRequest request) {
//		return Result.success(ManufactureResultConverter.toResponse(manufactureResultService.listManufactureResult(ManufactureResultConverter.toQuery(request))));
//	}
//
//	@PostMapping(value = "/count")
//	@Override
//	public Result<Integer> countManufactureResult(@RequestBody ListManufactureResultRequest request) {
//		return Result.success(manufactureResultService.countManufactureResult(ManufactureResultConverter.toQuery(request)));
//	}
//
    @PostMapping(value = "/page")
    @Override
    public Result<Page<GetManufactureResultResponse>> pageManufactureResult(@RequestBody ListManufactureResultRequest request) {
        ManufactureResultQuery query = ManufactureResultConverter.toQuery(request);
        List<GetManufactureResultResponse> list = ManufactureResultConverter.toResponse(manufactureResultService.listManufactureResult(query));
        int count = manufactureResultService.countManufactureResult(query);
        return Result.success(new Page<>(list, count));
    }

    @GetMapping(value = "/list_pre_options")
    public Result<Map<String, List>> listPreOptions() {
        Map<String, List> map = new HashMap<>();
        map.put("handOverResult", EnumUtils.toKeyValueList(HandOverResultEnum.values(),
                (e) -> ((HandOverResultEnum) e).getName()));
        return Result.success(map);
    }
}
